package com.gdssoft.pdaweb;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import junit.framework.TestCase;

import org.junit.Test;

import com.gdssoft.BaseTestCase;
import com.gdssoft.core.util.DateUtil;
import com.gdssoft.framework.dao.system.AppUserDao;
import com.gdssoft.pdaweb.dao.CheckTaskDao;
import com.gdssoft.pdaweb.dao.CheckWorkOrderDao;
import com.gdssoft.pdaweb.dao.CrmWorkOrderDao;
import com.gdssoft.pdaweb.dao.am.AmMonthPlanReadDao;
import com.gdssoft.pdaweb.dao.water.PdaWaterListDao;
import com.gdssoft.pdaweb.dao.water.WaterMeterMonthPlanReadDao;
import com.gdssoft.pdaweb.model.CheckTask;
import com.gdssoft.pdaweb.model.CheckWorkOrder;
import com.gdssoft.pdaweb.model.CrmWorkOrder;
import com.gdssoft.pdaweb.model.am.AmMonthPlanRead;
import com.gdssoft.pdaweb.model.water.PdaWaterList;
import com.gdssoft.pdaweb.model.water.WaterMeterMonthPlanRead;
import com.gdssoft.pdaweb.service.EamService;
import com.gdssoft.pdaweb.service.ws.PdaService;

public class PdaServiceTestCase extends BaseTestCase {
	@Resource
	private PdaService pdaService;
	@Resource
	private CrmWorkOrderDao crmWorkOrderDao;
	@Resource
	private CheckWorkOrderDao checkWorkOrderDao;
	@Resource
	private CheckTaskDao checkTaskDao;
	@Resource
	private AmMonthPlanReadDao amMonthPlanReadDao;
	@Resource
	private WaterMeterMonthPlanReadDao waterMeterMonthPlanReadDao;
	@Resource
	private com.gdssoft.pdaweb.service.ws.EamService eamWebService;
	@Resource 
	private EamService eamService;
	@Resource
	private AppUserDao appUserDao;
	@Resource
	private PdaWaterListDao pdaWaterListDao;
	@Test
	
	public void testPdaService() throws Exception{
		//syncApplyRepair();
		//insertApplyRepair();
		//testListUserRole();
		//testListRepairWorkOrder();
		//testQueryRepairWorkOrder();
		//testPushInspectionWorkTask();
		testListAmmeterReadingWorkOrder();
		//testUpdateAmmeterReadingWorkOrder();
		//queryWorkOrder("", "", "王", "", "", "2013-05-01 01:27:07", "2013-05-10 01:27:07", "test");
		//testUpdateRepairWorkOrder();
		//testQueryWorkOrder();
		//testVerifyAuth();
		//listAttachment();
		//insertMaterial();

		//insertApplyRepair();
		//testqueryWatermeterReadingWorkOrder();
		//queryWatermeterReadingWorkOrder("","","","admin");
		//testqueryAmmeterReadingWorkOrder();
		//testSyncRepairOrderStatus();

		//insertApplyRepair();
		//testListWatermeterReadingWorkOrder();
		//testUpdateRepairWorkOrder();
		//testListWorkOrder();
		//testPushMeterOperate();
		//testUpdateWatermeterReadingWorkOrder();
		testpushAssetInfo();
	}
	
	private void testPushMeterOperate(){
		boolean result = eamWebService.pushMeterOperate("12315", "110", "120", "6923790706362", "001A", "12315", "beargao", new Date());
		System.out.println(result+"--------------------------------------------");
	}
	private void testqueryWatermeterReadingWorkOrder()
	{
		String result = pdaService.queryWatermeterReadingWorkOrder("", "", "2013-05-01 12:14:30", "2013-06-08 12:14:30", "test");
		System.out.println(result+"--------------------------------------------");
	}
	private void alertRepairWorkStatus()
	{
		boolean result = eamWebService.alertRepairWorkStatus("13", "5");
        System.out.println(result); 
		
		System.out.println(result+"--------------------------------------------");
	} 

	private void insertApplyRepair()
	{
		String s=null;
		boolean result=pdaService.insertApplyRepair("11", "yuejun", "2013-5-21 12:00:00", "测试用例", "保修原因1","00123","0");
		System.out.println(result);
		
		System.out.println(result+"--------------------------------------------");
	}
	

	private void insertMaterial()
	{
		boolean result = pdaService.insertMaterial("14", "RE13060603", "6926456900920", "test", "1,2;2,55");  
        System.out.println(result); 
		
		System.out.println(result+"--------------------------------------------");
	}
	private void listAttachment()
	{
		String result = pdaService.listAttachment("3123");
        System.out.println(result); 
		
		System.out.println("--------------------------------------------");
	}
	
	/*private void testQueryWorkOrder() throws Exception{
	//String listStr = pdaService.queryWorkOrder("", "9", "", "", "","2012/04/01 13:24:55", "2014/04/01 13:24:55", "admin");
    String listStr = pdaService.queryWorkOrder("", "", "王", "", "", "2013-05-01 01:27:07", "2013-05-10 01:27:07", "test");
                                              
	TestCase.assertNotNull("返回值应该不为空", listStr);
	System.out.println(listStr);
	
	System.out.println("--------------------------------------------");
     }*/
	private void testListUserRole() {
		String roles = pdaService.listUserRoles("test");
		System.out.println(roles);
	System.out.println("-----------------------------------------------------");
	}
	
    /*private void testPushInspectionWorkTask() throws Exception{
	
		CheckWorkOrder  checkWorkOrder0 = new CheckWorkOrder();
		boolean dd=eamService.pushInspectionWorkOrder("001", "001", "beartest", "admin", "2013-03-15 12:00:00", "001", "001", "001","001", "001", "admin", "2013-03-15 12:00:00");
		eamService.pushInspectionWorkTask("001", "001", "001");
		Long result=0l;
		checkWorkOrderDao.get(18l);
		if (!checkWorkOrderDao.get(13l).equals(null))
		
		{result =1l;}
		else {
			//boolean dd=eamService.pushInspectionWorkOrder("142", "001", "beartest", "admin", "2013-03-15 12:00:00", "001", "001", "001","001", "001", "admin", "2013-03-15 12:00:00");
			//result =2l;	
			boolean results = eamService.pushAssetInfo("425111111108", "77888", "1050080316", "75245");
			//boolean result1 = eamService.pushInspectionWorkTask("1152","5434","7867");
		}
		System.out.println(results+"-----------------------------------------------------");
		System.out.println("维修"+dd+"-----------------------------------------------------");
	}
	*/
    private void testVerifyAuth() throws Exception{
		Long result = pdaService.verifyAuth("test", "123456", "CC:52:AF:BC:57:F0");
		//TestCase.assertNotNull("返回值应该不为空", result);
		//TestCase.assertTrue("返回值大于0", result>0);
		System.out.println(result+"--------------------------------------------");
	}
	
    private void testListWorkOrder() throws Exception{
		String listStr = pdaService.listWorkOrder("test");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr);
		
		System.out.println("--------------------------------------------");
	}
    private void testpushAssetInfo() throws Exception{
		boolean listStr = eamWebService.pushAssetInfo("1000000", "test", "111331008010326", "001", "sdfsd","sdfsd","504", "OPERATING", "69228682857302", "0","0");
		//TestCase.assertNotNull("返回值应该不为空", listStr);
		//System.out.println(listStr);
		
		System.out.println(listStr +"--------------------------------------------");
	}
   private void testQueryWorkOrder() throws Exception{
		String listStr = pdaService.queryWorkOrder("", "9", "", "", "", 
				"2012/04/01 13:24:55", "2014/04/01 13:24:55", "admin");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr);
		
		System.out.println("--------------------------------------------");
	}
	
   private void testUpdateWorkOrder() throws Exception{
		
		String sDate = DateUtil.dateFormat(new Date());
		
		Boolean b = pdaService.updateWorkOrder("2X-W3Q1", "1", sDate, sDate, "tester");
		TestCase.assertTrue("应该更新成功", b);
		CrmWorkOrder crmWorkOrder = crmWorkOrderDao.get(1L);
		
		TestCase.assertEquals("客服工单更新不成功", crmWorkOrder.getComment(), sDate);
		
		System.out.println("--------------------------------------------");
	}	
    private void testListCheckWorkOrder() throws Exception {
		String listStr = pdaService.listCheckWorkOrder("admin");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		//TestCase.a
		System.out.println("--------------------------------------------");
	}
	
   private void testListRepairWorkOrder() throws Exception {
		String listStr = pdaService.listRepairWorkOrder("test");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		//TestCase.a
		System.out.println("--------------------------------------------");
	}
  
	
    private void testQueryRepairWorkOrder() throws Exception {
		String listStr = pdaService.queryRepairWorkOrder(null, "1", null, "2013/4/1", null, "admin");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		//TestCase.a
		System.out.println("--------------------------------------------");
	}
	
   private void testUpdateRepairWorkOrder() throws Exception {
		boolean listStr = pdaService.updateRepairWorkOrder("14", "9", "过后", "test","2013-06-04 14:00:13","2013-06-04 14:00:58");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		//TestCase.a
		System.out.println("--------------------------------------------");
	}
////	
    private void testUpdateCheckWorkOrder() throws Exception{
		
		String sDate = DateUtil.dateFormat(new Date());
		
		boolean b = pdaService.updateCheckWorkOrder("12", "9", sDate, sDate, "tester","2013-2-21 09:00:00","2013-2-21 09:00:00");
		
		TestCase.assertTrue("应该更新成功", b);
		
		CheckWorkOrder checkWorkOrder = checkWorkOrderDao.get(12L);
		
		TestCase.assertEquals("巡检工单更新不成功", checkWorkOrder.getWorkComment(), sDate);
		
		System.out.println("--------------------------------------------");
	}
	
   private void testListCheckTaskByAssignmentId() throws Exception {
		String listStr = pdaService.listCheckTaskByAssignmentId("12");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		
		System.out.println("--------------------------------------------");
	}
	
    private void testUpdateCheckTask() throws Exception{
		
		String sDate = DateUtil.dateFormat(new Date());
		
		boolean b = pdaService.updateCheckTask("12", "1", "9", sDate, "tester");
		
		TestCase.assertTrue("应该更新成功", b);
		
		CheckTask checkTask = checkTaskDao.getByUniqueKey(12L, 1L);
		
		TestCase.assertNotNull("返回值应该不为空", checkTask.getExstatusDate());
		
		TestCase.assertEquals("巡检工单任务更新不成功", 
				DateUtil.dateFormat(checkTask.getExstatusDate()), sDate);
		
		System.out.println("--------------------------------------------");
	}
	
    private void testListWatermeterReadingWorkOrder() throws Exception {
		String listStr = pdaService.listWatermeterReadingWorkOrder("test");
		//TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		
		System.out.println("--------------------------------------------");
	}
	
    private void testUpdateWatermeterReadingWorkOrder() throws Exception{
		
		String sDate = DateUtil.dateFormat(new Date());
		
		boolean b = pdaService.updateWatermeterReadingWorkOrder("1", "152", sDate, "tester");
		
		TestCase.assertTrue("应该更新成功", b);
		
		WaterMeterMonthPlanRead waterMeterMonthPlanRead = waterMeterMonthPlanReadDao.get(1L);
		
		TestCase.assertEquals("水表读数更新不成功", DateUtil.dateFormat(waterMeterMonthPlanRead.getReadingTime()), sDate);
		
		System.out.println("--------------------------------------------");
	}
	
    private void testListAmmeterReadingWorkOrder() throws Exception {
		String listStr = pdaService.listAmmeterReadingWorkOrder("testam");
		TestCase.assertNotNull("返回值应该不为空", listStr);
		System.out.println(listStr); 
		
		System.out.println("--------------------------------------------");
	}

    private void testUpdateAmmeterReadingWorkOrder() throws Exception{
		
		Long id = 2513L;
    	String sDate = "2013-05-04 03:05:18";
		
		boolean b = pdaService.updateAmmeterReadingWorkOrder(id.toString(), "45", sDate, "test");
		
		TestCase.assertTrue("应该更新成功", b);
	
		AmMonthPlanRead amMonthPlanRead = amMonthPlanReadDao.get(id);
		
		TestCase.assertEquals("电表读数更新不成功", DateUtil.dateFormat(amMonthPlanRead.getReadingTime()), sDate);
		
		System.out.println("--------------------------------------------");
	}
    private void testqueryAmmeterReadingWorkOrder() throws Exception{
    	String check =  pdaService.queryAmmeterReadingWorkOrder("","", "2013-05-01 12:14:30", "2013-06-04 12:14:30", "test");
    	System.out.println(check+"--------------------------------------------");
    	
    }
    }
		
